<?php
include("../config.php");
include("../inc/func.php");
include("../db.php");
$debug = TRUE;
loginCheck();
//SQLness
$query1 = "SELECT value FROM `$db_prefix"."main` WHERE `option` = 'title'";
$result1 = mysql_query($query1);
while($row1 = mysql_fetch_row($result1)) {
$sitename = $row1[0];
}
$query2 = "SELECT value FROM `$db_prefix"."main` WHERE `option` = 'subtitle'";
$result2 = mysql_query($query2);
while($row2 = mysql_fetch_row($result2)) {
$subtitle = $row2[0];
}
$query = "SELECT value FROM `$db_prefix"."main` WHERE `option` = 'postlimit'";
$result = mysql_query($query);
while($row = mysql_fetch_row($result)) {
$postlimit = $row[0];
}
if($_GET['update']) {
	$newname = $_POST['title'];
	$newsub = $_POST['subtitle'];
	$newlimit = $_POST['limit'];
	$newpass1 = $_POST['pass1'];
	$newpass2 = $_POST['pass2'];
	if($newpass1 == $newpass2) {$newpass = md5($newpass1);}
	else {header("Location: options.php?error=pass");}
	if(empty($newpass1) && empty($newpass2)) { }
	else {
		$query = "UPDATE `$db_prefix"."main` SET `value` = '$newpass' WHERE `$db_prefix"."main`.`option` = 'pass' LIMIT 1";
		$result = mysql_query($query);
    }
	if(empty($newname) || empty($newsub) || empty($newlimit)) {header("Location: options.php?error=empty");}
	else {
		$query = "UPDATE `$db_prefix"."main` SET `value` = '$newname' WHERE `$db_prefix"."main`.`option` = 'title' LIMIT 1";
		$result = mysql_query($query);
		$query = "UPDATE `$db_prefix"."main` SET `value` = '$newsub' WHERE `$db_prefix"."main`.`option` = 'subtitle' LIMIT 1";
		$result = mysql_query($query);
		$query = "UPDATE `$db_prefix"."main` SET `value` = '$newlimit' WHERE `$db_prefix"."main`.`option` = 'postlimit' LIMIT 1";
		$result = mysql_query($query);
		header("Location: options.php?updated=1");
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php site_title();?> Control Panel - Options</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="wrap">
  <div id="head">
    <div id="title"><?php site_title(); ?><div class="gotosite"> <a href="../">Go to your site &raquo;</a></div></div>
  </div>
  <div id="nav">
    <ul>
      <li><a href="index.php">Main</a></li>
      <li><a href="post.php">Post</a></li>
      <li><a href="manage.php">Manage</a></li>
      <li><a href="theme.php">Themes</a></li>
      <li class="current"><a href="options.php">Options</a></li>
    </ul>
  </div>
  <div id="content">
  <?php
  if($_GET['error']) {
  echo "<div class=\"deleteme\">";
	switch($_GET['error']) {
		case "pass";
			echo "Passwords do not match";
		break;
		case "empty";
			echo "Not all the fields are filled in";
		break;
		}
	echo "</div>";
  }
  if($_GET['updated']) {
	  echo "<div id=\"success\">Updated successfully</div>";
  }
  ?>
  <form id="postform" method="post" action="?update=1">
    <div class="formtitle">Site name</div>
    <input type="text" id="posttitle" cols="80" name="title" value="<?php ec($sitename);?>" /><br /><br />
    <div class="formtitle">Site subtitle</div>
    <input type="text" id="posttitle" cols="80" name="subtitle" class="link" value="<?php ec($subtitle);?>" /><br /><br />
    <div class="formtitle">Posts per page (current: <?php ec($postlimit); ?>)</div>
    <select name="limit">
      <option value="5">5</option>
      <option value="6" class="alt">6</option>
      <option value="7">7</option>
      <option value="8" class="alt">8</option>
      <option value="9">9</option>
      <option value="10" class="alt">10</option>
      <option value="11">11</option>
      <option value="12" class="alt">12</option>
      <option value="13">13</option>
      <option value="14" class="alt">14</option>
      <option value="15">15</option>
    </select><br /><br />
    <div class="formtitle">New password</div>
    <input type="password" id="posttitle" cols="80" name="pass1" class="link" /><br /><br />
    <div class="formtitle">New password again</div>
    <input type="password" id="posttitle" cols="80" name="pass2" class="link" /><br /><br />
    <input type="submit" value="Update" class="postbutton" />
  </form>
  </div>
  <div id="footer"><?php LIversion(); ?></div>
</div>
</body>
</html>
